import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    home: Scaffold(
      appBar: AppBar(
        title: const Text("Event And Notification Widget Demo"),
      ),
      body: const GestureRecognizerWidget(),
    ),
  ));
}

class GestureRecognizerWidget extends StatefulWidget {
  const GestureRecognizerWidget({Key? key}) : super(key: key);

  @override
  _GestureRecognizerWidgetState createState() => _GestureRecognizerWidgetState();
}

class _GestureRecognizerWidgetState extends State<GestureRecognizerWidget> {

  TapGestureRecognizer _tapGestureRecognizer = TapGestureRecognizer();
  bool _toggle = false;


  @override
  void dispose() {
    _tapGestureRecognizer.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text.rich(
        TextSpan(
          children:[
            const TextSpan(text: '你好世界'),
            TextSpan(
                text: "点我变色",
                style: TextStyle(
                  fontSize: 30.0,
                  color: _toggle ? Colors.blue : Colors.red,
                ),
                recognizer: _tapGestureRecognizer
                  ..onTap =() {
                    setState(() => _toggle = !_toggle);
                  }
            ),
            const TextSpan(text: '你好世界'),
          ]
        ),
      ),
    );
  }
}
